package com.zzmx.springboot.atomikos.service;

import com.zzmx.springboot.atomikos.entity.UserEntity;
import com.zzmx.springboot.atomikos.enums.UserSexEnum;
import com.zzmx.springboot.atomikos.mapper.test1.User1Mapper;
import com.zzmx.springboot.atomikos.mapper.test2.User2Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author liuxc
 * @Description:
 * @create 2018-04-16 17:56
 **/
@Service
public class TestServiceImpl {

    @Autowired
    private User1Mapper user1Mapper;

    @Autowired
    private User2Mapper user2Mapper;

    @Transactional(value = "transactionManager", rollbackFor = RuntimeException.class)
    public void test() {
        System.out.println("begin.....");
        user1Mapper.insert(new UserEntity("aa", "a123456", UserSexEnum.MAN));
        user1Mapper.insert(new UserEntity("bb", "b123456", UserSexEnum.WOMAN));
        user1Mapper.insert(new UserEntity("cc", "b123456", UserSexEnum.WOMAN));
        user2Mapper.insert(new UserEntity("aa", "a123456", UserSexEnum.MAN));
        user2Mapper.insert(new UserEntity("bb", "b123456", UserSexEnum.WOMAN));
        user2Mapper.insert(new UserEntity("cc", "b123456", UserSexEnum.WOMAN));
        System.out.println("end.....");
//        throw new RuntimeException();
//        throw new RuntimeException("rollback");
    }
}
